package com.aduerr.v1shouyin.mvp.adpter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.entity.GetMemberListEntity;
import com.aduerr.v1shouyin.mvp.activity.MemberInchargListItemDetailActivity;
import com.aduerr.v1shouyin.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类名: stickrecycleadpter
 * 此类用途: ---
 *
 * @Author: peixi
 * @Date: 2017-12-08 09:06
 * @Email: cr7inmanchester.com
 * @FileName: com.aduer.shouyin.mvp.activity.stickrecycleadpter.java
 */
public class MemberInchargListAdpter extends RecyclerView.Adapter {
    private Context context;
    private List<GetMemberListEntity.DataBean> outdataBeen = new ArrayList<>();
    private ViewHolder viewHolder;

    public MemberInchargListAdpter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView =
                LayoutInflater.from(context).inflate(R.layout.item_memberincharglist,
                        parent, false);
        viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //type 是0  充值
        if(outdataBeen.size() > 0) {
            viewHolder = (ViewHolder) holder;
            viewHolder.tv_money.setText(outdataBeen.get(position).getMoney());
            viewHolder.tv_time.setText(outdataBeen.get(position).getCreatetime());
            viewHolder.tv_phone.setText(outdataBeen.get(position).getPhone());
            viewHolder.tv_type.setText("充值成功");
            //条目点击事件+
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context,
                            MemberInchargListItemDetailActivity.class);
                    intent.putExtra("date", outdataBeen.get(position));
                    context.startActivity(intent);
                }
            });
        }
    }


    @Override
    public int getItemCount() {
        return outdataBeen.size();
    }

    public void refresh(List<GetMemberListEntity.DataBean> dataBeen) {
        outdataBeen.clear();
        for(GetMemberListEntity.DataBean dataBean : dataBeen) {
            String type = dataBean.getType();
            if(type.equals("0")) {//充值
                outdataBeen.add(dataBean);
            }
        }
        notifyDataSetChanged();
    }

    //加载更多
    public void loadmore(List<GetMemberListEntity.DataBean> dataBeen) {
        if(dataBeen.size() == 0) {
            ToastUtils.showToast(context, "没有数据");
        } else {
            for(GetMemberListEntity.DataBean dataBean : dataBeen) {
                String type = dataBean.getType();
                if(type.equals("0")) {//充值
                    outdataBeen.add(dataBean);
                }
            }
        }
        notifyDataSetChanged();
    }


    //普通的条目
    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_phone)
        TextView tv_phone;
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.ll_containt_detail)
        RelativeLayout llContaintDetail;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
